import request from '@/utils/request'

/**
 * 获取频道列表数据
 * @returns
 */
export const getChannels = () => {
  return request('channels', 'get')
}

/**
 * 获取文章列表数据
 * @param {*} params 多个参数对象,如 {status,channel_id,begin_pubdate,end_pubdate,page,per_page}
 * @returns
 */
export const getArticles = (params) => {
  return request('mp/articles', 'get', params)
}

/**
 * 删除文章
 * @param {String} id
 * @returns
 */
export const delArticle = (id) => {
  return request(`/mp/articles/${id}`, 'delete')
}

/**
 * 发表文章
 * @param {Boolean} draft 是否存草稿，true为存草稿，false为不存草稿
 * @param {Obj} data
 * @returns Promise
 */
export const addAritcle = (data, draft) => {
  return request(`/mp/articles?draft=${draft}`, 'post', data)
}

/**
 * 获取文章详细信息
 * @param {String} id
 * @returns Promise
 */
export const getArticleByIdApi = (id) => {
  return request(`/mp/articles/${id}`, 'get')
}

/**
 * 修改文章
 * @param {*} data
 * @param {*} draft
 * @returns Promise
 */
export const updateArticle = (data, draft = false) => {
  return request(`/mp/articles/${data.id}?draft=${draft}`, 'put', data)
}
